home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / mkpass.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  1KB  |  69 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: mkpass.c,v 1.6 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <stdio.h>
  8. #include <time.h>
  9. #ifndef WIN32
  10. #include <unistd.h>
  11. #endif
  12. #include <stdlib.h>
  13. #include "opennap.h"
  14. #include "debug.h"
  15.  
  16. /* needed for the random number generation */
  17. time_t Current_Time = 0;
  18.  
  19. static void
  20. usage (void)
  21. {
  22.     fputs ("usage: mkpass [ -c INFO ] PASSWORD\n", stderr);
  23.     exit (1);
  24. }
  25.  
  26. int
  27. main (int argc, char **argv)
  28. {
  29.     char *s, *pass = 0;
  30.     int i;
  31.  
  32.     INIT ();
  33.  
  34.     while ((i = getopt (argc, argv, "c:vh")) != -1)
  35.     {
  36.         switch (i)
  37.         {
  38.         case 'c':
  39.             pass = optarg;
  40.             break;
  41.         default:
  42.             usage ();
  43.         }
  44.     }
  45.  
  46.     if (!argv[optind])
  47.         usage ();
  48.  
  49.     if (pass)
  50.     {
  51.         if (check_pass (pass, argv[optind]))
  52.             puts ("invalid password");
  53.         else
  54.             puts ("OK");
  55.     }
  56.     else
  57.     {
  58.         Current_Time = time (0);
  59.         init_random ();
  60.         s = generate_pass (argv[optind]);
  61.         puts (s);
  62.         if (check_pass (s, argv[optind]))
  63.             puts ("error");
  64.         FREE (s);
  65.         CLEANUP ();
  66.     }
  67.     exit (0);
  68. }
  69.